<?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('facebook-sdk/src/facebook.php');

  $config = array(
    'appId' => '120005274854592',
    'secret' => 'a7f7790809678a06dba58eec8c3b5aca',
  );

  $facebook = new Facebook($config);
  $access = $facebook->getAccessToken();
  $user_id = $facebook->getUser();
  //echo $access;
  
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {
    
      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        $user_profile = $facebook->api('/me?fields=friends','GET');
                echo "<table>";
		foreach($user_profile['friends'] as $key)
		{
                        echo "<tr>";
			foreach($key as $num)
				echo "<td><b>Name:".$num['name']."</b></td><td><i> Identification:".$num['id']."</i></td><td>"."<img src='https://graph.facebook.com/".$num['id']."/picture' width='50' height='50' title='".$num['name']."' /></td>";
                        echo "<br></tr>";
		}
                echo "</table>";
        //echo "Name: " . $user_profile['name'];
		//echo "<br>Id:" . $user_profile['id'];

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
          $param = 'friends_about_me,friends_action.music,friends_actions.news,friends_actions.video,
                    friends_activities,friends_birthday,friends_education_history,
                    friends_events';
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Opps!!! You are not logged in to Samay Ville App Yet :( -  <a href="' . $login_url . '">Login Here.</a>';

    }

  ?>

  </body>
</html>